[Popup] Properly handle Android Back Button pressed#2716
Merged
TheCodeTraveler merged 8 commits intomainfrom Jun 13, 2025
Merged
[Popup] Properly handle Android Back Button pressed#2716TheCodeTraveler merged 8 commits intomainfrom
TheCodeTraveler merged 8 commits intomainfrom
Conversation
Contributor
There was a problem hiding this comment.
Pull Request Overview
This PR ensures that tapping the Android Back button properly closes the popup by calling CloseAsync() and uses SafeFireAndForget(), so the ShowPopupAsync() task completes as expected.
- Removed the unused
Shell.SetPresentationModeblock in the constructor. - Added
CommunityToolkit.Maui.ExtensionsforSafeFireAndForget. - Updated
OnBackButtonPressedto always callCloseAsync(...)and returntrueinstead of delegating tobase.
Comments suppressed due to low confidence (1)
src/CommunityToolkit.Maui/Views/Popup/PopupPage.shared.cs:113
- Consider adding unit or integration tests for
OnBackButtonPressedto verify thatCloseAsyncis invoked and thatShowPopupAsync()completes when the Android Back button is pressed.
CloseAsync(new PopupResult(true), CancellationToken.None).SafeFireAndForget();
Closed
2 tasks
bijington
reviewed
Jun 13, 2025
bijington
previously approved these changes
Jun 13, 2025
bijington
approved these changes
Jun 13, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description of Change
This PR updates
protected override bool PopupPage.OnBackButtonPressed()to ensure we properly close the Popup usingCloseAsync()when the Android Back Button is tapped by the user.This ensures that the
Taskreturned byShowPopupAsync()completes when the Android Back Button is tapped.Linked Issues
Fixes #2717
Fixes #2700
This fixes the Issue highlighted by @crwsolutions in their comment here: #2703 (comment).
Note: This does not close resolve the issue #2703. We currently unable to reproduce that Issue and are awaiting a sample reproduction to help us solve that Issue.
PR Checklist
approved(bug) orChampioned(feature/proposal)mainat time of PRAdditional information
SafeFireAndForget
Because
protected override bool OnBackButtonPressed()does not return aTask, we are unable to use theawaitkeyword. SincePopupPage.Closereturns aTask, we use.SafeFireAndForget()to ensure we follow best practices and await itsTaskunder the hood.PopupResult
For the
PopupResult, I am settingWasDismissedByTappingOutsideOfPopuptotruefor two reasons:WasDismissedByTappingOutsideOfPopup = falserequiresPopupResult<T>.Resultto be a value provided by the developer when programmatically closing the popup